insert condition in a object javascript

49

insert condition in a object javascript -

const arr = [
  ...(isConditionTrue() ? [{
    key: 'value'
  }] : [])
];

const obj = {
  ...(isConditionTrue() ? {key: 'value'} : {})
};

insert condition in a object javascript -

const a = {
   ...(someCondition && {b: 5})
}

Comments

Submit
0 Comments